
class util {
  transformArray(arr:Array<any>, idKey:any = 'value', nameKey:string = 'label'){
    let data = [];
    if(arr.length  > 0){
        data = arr.map(item => {
           item.id = item[idKey];
           item.name = item[nameKey];
           return item;
        });
    }else{
        data = []
    }
    return data;
  };
  selectName(val:any, arr:any[], keyId:string = 'id', keyName:string = 'name'){
    let obj = arr.find(item => item[keyId] == val);
    if(obj){
        return obj[keyName];
    }else{
        return null;
    }        
  };
  resetForm(form1:any, form2:any){
    let obj = JSON.parse(JSON.stringify(form2));
    for(var key in form1){
        if(form2.hasOwnProperty(key)){
            form1[key] = obj[key];
        };
    }
  };
}

export default new util();